﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace P2PLib.Client.Command
{
    public class CCStopTransferCommand:CCCommandBase
    {
        private string fileHashCode;
        public string FileHashCode {
            get {
                return this.fileHashCode;
            }
            set {
                this.fileHashCode = value;
            }
        }
        public CCStopTransferCommand()
            : base(CCCommandType.StopTransfer)
        {
            fileHashCode = string.Empty;
        }
        public CCStopTransferCommand(string code)
            : base(CCCommandType.StopTransfer)
        {
            fileHashCode = code;
        }
        public override void ReadFromStream(System.IO.Stream stream)
        {
            byte[] buffer = new byte[4];
            stream.Read(buffer, 0, 4);
            int size = BitConverter.ToInt32(buffer, 0);
            buffer = new byte[size];
            stream.Read(buffer, 0, size);
            this.fileHashCode = Encoding.ASCII.GetString(buffer);
        }
        public override void WriteToStream(System.IO.Stream stream)
        {
            byte[] buffer = Encoding.ASCII.GetBytes(fileHashCode);
            stream.Write(BitConverter.GetBytes(buffer.Length), 0, 4);
            stream.Write(buffer, 0, buffer.Length);
        }
    }
}
